$s = $value ? 'true' : 'false';
} elseif ( is_null( $value ) ) {
$s = 'null';
- } elseif ( is_int( $value ) ) {
- $s = $value;
+ } elseif ( is_int( $value ) || is_float( $value ) ) {
+ $s = strval($value);
} elseif ( is_array( $value ) && // Make sure it's not associative.
array_keys($value) === range( 0, count($value) - 1 ) ||
count($value) == 0
'encodeJsVar() with object'
);
}
+
+ function testEncodeJsVarInt() {
+ $this->assertEquals(
+ '123456',
+ Xml::encodeJsVar( 123456 ),
+ 'encodeJsVar() with int'
+ );
+ }
+
+ function testEncodeJsVarFloat() {
+ $this->assertEquals(
+ '1.23456',
+ Xml::encodeJsVar( 1.23456 ),
+ 'encodeJsVar() with float'
+ );
+ }
+
+ function testEncodeJsVarIntString() {
+ $this->assertEquals(
+ '"123456"',
+ Xml::encodeJsVar( '123456' ),
+ 'encodeJsVar() with int-like string'
+ );
+ }
+
+ function testEncodeJsVarFloatString() {
+ $this->assertEquals(
+ '"1.23456"',
+ Xml::encodeJsVar( '1.23456' ),
+ 'encodeJsVar() with float-like string'
+ );
+ }
}